﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CapaNegocio;
using Excepciones;

namespace CapaUsuario
{
    public partial class BajaCliente : Form
    {
        private Admin admin;
        public BajaCliente(Admin a)
        {
            admin=a;
            InitializeComponent();
            dataGridView1.DataSource=admin.listar("cliente");
        }


        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int nroDni = (int)dataGridView1.CurrentRow.Cells[0].Value;
                if (admin.bajaCliente(nroDni) == true)
                    MessageBox.Show("el cliente con dni " + nroDni + " ha sido dado de baja ");
                else
                    MessageBox.Show(" el cliente no existe ");
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (DataException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                //actualizo el datagridview
                dataGridView1.DataSource = admin.listar("cliente");
            }

        }



    }
}
